def prime_number(num): 
    if num%2==0:  
        return num==2
    chislo = 3
    while chislo*chislo<=num and num%chislo!=0:
        chislo=chislo+2
    return chislo*chislo>num


words=input().split()
num_num=["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
num_n={"zero" : 0,  "one":1 , "two":2 , "three":3 , "four":4 , "five":5 , "six":6 , "seven":7 , "eight":8 , "nine":9}
nu='' 
W_input=False
for i in words:   
    if i not in num_num:
        W_input=True
    else: 
        nu=nu + str(num_n.get(i))  
if W_input == False:
    if len(words) != 3:  
        W_input = True
    else:  
        nu=int(nu)

        
if W_input == False: 
    nplus = nu  
    while prime_number(nplus)!=True: 
       nplus=nplus+1 

    nminus = nu 
    while prime_number(nminus)!=True: 
       nminus= nminus-1

if W_input == False:  
    if nplus - nu > nu - nminus: 
       print(nminus) 
    else: 
        print(nplus)
else:
    print("Wrong input") 
